﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace AspNetSimple
{
    public class Email
    {
        // 19926043614@163.com
        public static void Send(string host)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            msg.To.Add(host);

            msg.From = new MailAddress("eye@fool.com", "fool man", System.Text.Encoding.UTF8);
            /* 上面3个参数分别是发件人地址（可以随便写），发件人姓名，编码*/
            msg.Subject = "Something acquired by accident";//邮件标题
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码  
            msg.Body = "not fit to be seen";//邮件内容  
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码  
            msg.IsBodyHtml = false;//是否是HTML邮件  
            msg.Priority = MailPriority.High;//邮件优先级
            msg.Attachments.Add(new Attachment(@"C:\Users\Administrator\Pictures\20220817111218.jpg", "image/jpeg"));
            SmtpClient client = new SmtpClient();
            client.Host = "localhost";
            object userState = msg;
            try
            {
                client.SendAsync(msg, userState);
                Console.WriteLine("Mail OK");
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
